/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon, Kinshuk Mishra
 												Neha Sugandh
 												
Class							:				Wargus Main
 
Function						: 				The class provides a  hook to start
												Wargus
*********************************************************************************/

package base;

import java.util.LinkedList;

import mre.MRE;
import tacticalLayer.ScriptedTacticalLayer;
import tacticalLayer.TacticalLayer;
import cbr.CBR;
import cbr.episodicCBR.EpisodicCBR;

public class Wargusmain extends CBLILRModule {
	protected LinkedList<CBLILRModule> m_modules=new LinkedList<CBLILRModule>();
	protected ProxyBot m_pb;	// This allows us to read the game state from Wargus
	
	public Wargusmain(ProxyBot a_pb) {		
		super();
		m_pb = a_pb;
	}
	/*
	 * Start all the different modules 
	 * 
	 */
	public void run(){
		
		MRE m3 = null;
		
		System.out.println("MAIN: Creating the Wargus CBR engine...");
				
		{
//			CBR m1=new SimpleCBR();					
//			if (m_paths!=null) for(String s:m_paths) m1.loadCases(s);

			CBR m1=new EpisodicCBR();
			
//			TacticalLayer m2=new SimpleTacticalLayer(m_pb);
			TacticalLayer m2=new ScriptedTacticalLayer(m_pb);
			try	{
				m3=new MRE(m_pb,m1,m2);
				m_modules.add(m1);
				m_modules.add(m2);
				m_modules.add(m3);
			} catch(Exception e) {
				System.exit(0);
			}
			
		}

		System.out.println("MAIN: Starting the Wargus CBR engine...");
		
		for(CBLILRModule m: m_modules) m.start();

		while(!m_stopSignal) {
			try {
				if (m3.stopped()) m_stopSignal = true;
				Thread.sleep(100);
			} catch(Exception e) {
			}
		}

		System.out.println("MAIN: Stopping the Wargus CBR engine...");

		for(CBLILRModule m: m_modules) m.stop();
		for(CBLILRModule m: m_modules) m.join();
	}
}

